<?php
/**
 * 描述：船厂-船厂列表。
 * @final
 */
final class Exec_Shipyard_Account_List extends Exec
{
    public function Get()
    {
        #绑定数据-经营模式        
        View::Assign('Shipyard_Index_BusinessModel',DAO_BusinessModel::GetData());

        #获取参数
        $type=Functions::UrlArgs('type');

        #定义标量
        $contentTitle=NULL;
        $data=NULL;
        $params=array('type'=>$type);

        #执行动作
        switch($type)
        {
            case 'search':
                $contentTitle='搜索船厂信息';                
                $province=@$_GET['province'];
                $city=@$_GET['city'];
                $category=@$_GET['category'];
                $model=@$_GET['model'];
                $companyName=@$_GET['companyname'];                

                $sqlParams=array();
                $sql='select * from account ';
                $sql=$sql.'where not exists(select * from account_locked where account.Username=account_locked.Account) ';                      //不锁定
                $sql=$sql.'and not exists(select * from account_delete where account.Username=account_delete.Account) ';                        //没删除
                $sql=$sql.'and exists(select * from account_email_verification where account.Username=account_email_verification.Account) ';    //己通过邮件验证
                $sql=$sql.'and (';                                                                                                              //属于船厂
                $sql=$sql."(concat(',',Trade_Class,',') regexp concat(',(',replace('".Filter::Mysql_Contact(DAO_Trade::ShipIndustry_VALUE)."',',','|'),'),')) ";
                $sql=$sql.") ";
                {
                    if(is_numeric($province)&&(int)$province!=-1)
                    {
                        $sql=$sql.'and Province=? ';
                        $sqlParams[]=$province;
                        $params['province']=$province;
                    }
                    
                    if(is_numeric($city)&&(int)$city!=-1)
                    {                  
                        $sql=$sql.'and City=? ';
                        $sqlParams[]=$city;
                        $params['city']=$city;
                    }

                    if(is_numeric($category)&&$category!=-1)
                    {
                        $sql=$sql.'and Trade_Subclass=? ';
                        $sqlParams[]=$category;
                        $params['category']=$category;
                    }

                    if($model!=''&&$model!=NULL)
                    {
                        $sql=$sql.'and Model=? ';
                        $sqlParams[]=$model;
                        $params['model']=$model;
                    }

                    if($companyName!=''&&$companyName!=NULL)
                    {
                        $sql=$sql.'and CompanyName like ? ';
                        $sqlParams[]='%'.$companyName.'%';
                        $params['companyname']=$companyName;
                    }
                }
                $sql=$sql.'order by Datetime desc limit ?,10';
                $data=DB::PGetData($sql,$sqlParams);
            break;
            default:
                $contentTitle='最新船厂信息';
                $sql='select * from account ';
                $sql=$sql.'where not exists(select * from account_locked where account.Username=account_locked.Account) ';                      //不锁定
                $sql=$sql.'and not exists(select * from account_delete where account.Username=account_delete.Account) ';                        //没删除
                $sql=$sql.'and exists(select * from account_email_verification where account.Username=account_email_verification.Account) ';    //己通过邮件验证
                $sql=$sql.'and (';                                                                                                              //属于船厂
                $sql=$sql."(concat(',',Trade_Class,',') regexp concat(',(',replace('".Filter::Mysql_Contact(DAO_Trade::ShipIndustry_VALUE)."',',','|'),'),')) ";
                $sql=$sql.") ";
                $sql=$sql.'order by Datetime desc limit ?,20';                
                $data=DB::GetData($sql);
            break;
        }

        #数据处理
        foreach($data['Record'] as &$row)
        {
            //是否VIP
            $tmp=DB::PGetRows('select * from account_vip where Account=?',array(
                $row['Username']
            ));
            if($tmp){
                $row['IsVIP']='TRUE';
            }
            else{
                $row['IsVIP']='FALSE';
            }
            //商业模式
            $row['Model']=DAO_BusinessModel::GetName($row['Model']);
        }

        #渲染输出
        View::Assign('Shipyard_List_ContentTitle',$contentTitle);
        View::Assign('Shipyard_List_Account',@$data['Record']);
        View::Assign('Shipyard_List_PageMenu',PagerFactory::Create('Common')->Fetch($data,array
        (
            'URL'=>'/exec.php?action=shipyard_account_list','IsDetail'=>TRUE,
            'Parameters'=>$params,
            'Rewriter'=>($type=='search') ? NULL:new PagerRewrite('/shipyard/','type','html')
        )));
        View::Display('shipyard/account/list.tpl');
    }
}
?>